package sctu.edu.java.year2016.team02.project.pc.UI;

import sctu.edu.java.year2016.team02.project.pc.loginMan.PcOperator;
import sctu.edu.java.year2016.team02.project.pc.problem.SocketListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

/**
 * Created by Eoly on 2016/6/11.
 */
//客户端的初始化界面
public class InitUI extends JFrame implements ActionListener{
    private Button submit;
    private Button search;
    private Button login;
    private PcOperator pc;

    public InitUI(String title,PcOperator pc){
        super(title);
        this.pc = pc;
        init();
        setBounds(SocketListener.screenWidth / 4, SocketListener.ScreenHeight / 4, 400, 300);
        setLayout(null);
        add(submit);
        add(login);
        add(search);
        setVisible(true);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    private void init(){
        submit = new Button("Submit...");
        submit.addActionListener(this);
        search = new Button("Searching...");
        search.addActionListener(this);
        login = new Button("Login for Admin...");
        login.addActionListener(this);
        submit.setBounds(75,40,250,40);
        search.setBounds(75,110,250,40);
        login.setBounds(75,180,250,40);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==submit){
            new SubmitUI(this,"Submitting",pc,true);
        }
        if(e.getSource()==search){
            try {
                new SearchUI(this,"Searching",pc,true);
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        }
        if(e.getSource()==login){
            LoginUI LUI = new LoginUI(this,"Logining",true);
            if(LUI.isRight){
                setVisible(false);
                pc.isAD=true;
                new AdminUI("Admin",pc);
            }
        }
    }
}
